{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "comps = pd.read_csv(\"/kaggle/input/meta-kaggle/Competitions.csv\")\n",
    "evaluation = ['EvaluationAlgorithmAbbreviation',\n",
    "              'EvaluationAlgorithmName',\n",
    "              'EvaluationAlgorithmDescription',]\n",
    "compt = ['Title', 'EnabledDate', 'HostSegmentTitle']\n",
    "df = comps[compt + evaluation].copy()\n",
    "df['year'] = pd.to_datetime(df.EnabledDate).dt.year.values\n",
    "df['comps'] = 1\n",
    "time_select = (df.year >= 2017) & (df.year <= 2023)\n",
    "competition_type_select = df.HostSegmentTitle.isin(\n",
    "\t\t\t\t\t\t['Featured', 'Research'])\n",
    "pd.pivot_table(df[time_select&competition_type_select],\n",
    "               values='comps',\n",
    "               index=['EvaluationAlgorithmAbbreviation'],\n",
    "               columns=['year'],\n",
    "               fill_value=0.0,\n",
    "               aggfunc=np.sum,\n",
    "               margins=True\n",
    "              ).sort_values(\n",
    "                by=('All'), ascending=False).iloc[1:,:].head(20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "metric = 'AUC'\n",
    "metric_select = df['EvaluationAlgorithmAbbreviation']==metric\n",
    "print(df[time_select&competition_type_select&metric_select]\n",
    "        [['Title', 'year']])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "sel_df = df[time_select & competition_type_select]\n",
    "counts = sel_df.groupby('EvaluationAlgorithmName')\n",
    "total_comps_per_year = sel_df.groupby('year').count()[['comps']]\n",
    "single_metrics_per_year = (counts.sum()[counts.sum().comps == 1]\n",
    "       .groupby(['year', 'EvaluationAlgorithmName'])\n",
    "       .count()[['comps']])\n",
    "tot_single_metrics_per_year = (single_metrics_per_year.reset_index()\n",
    "                               .groupby('year')\n",
    "                               .count()['comps'])\n",
    "table =  tot_single_metrics_per_year / total_comps_per_year['comps']\n",
    "print(table)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print(counts.sum()[counts.sum().comps==1].index.values)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.8.9 64-bit",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.9"
  },
  "vscode": {
   "interpreter": {
    "hash": "7bbd5cde17810fda41d7e4dc10f0ac1bda638c18f4a90bb6d9a86160ca3be244"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
